<?php
class block_cleanup extends block_base 
{
	public function init() 
    {
        $this->title   = get_string('title', 'block_cleanup');
        $this->version = 2013030600;
		$this->cron	   = 3600*12;
    }
	
	function preferred_width() {
        return 210;
    }
    
	function applicable_formats() {
        return array('all' => true, 'tag' => false);   // Needs work to make it work on tags MDL-11960
    }
	
    public function get_content() 
    {
        global $CFG;
        
		if ( !has_capability("block/cleanup:block_access", get_context_instance(CONTEXT_SYSTEM)))
		{
			return '';
		}
		
	    if ($this->content !== NULL) 
	    {
		    return $this->content;
	    }
        
        $this->content    =  new stdClass;
        $text = "<div align='center'><form class='block_cleanup_form' action='".$CFG->wwwroot."/blocks/cleanup/delete.php' method='post'>
                <p class='sectiontitle'>".get_string("delete_inactive_users", "block_cleanup")."</p>
                <input type='hidden' name='dtype' value='users' />
                <input type='submit' name='fd_submit' value='>' title='"
                .get_string('launch_script', 'block_cleanup')."'/>
                </form>";
        
        // создаем форму для удаления файлов
        $form = "<form class='block_cleanup_form' action='".$CFG->wwwroot."/blocks/cleanup/delete.php' method='post'>
                <p class='sectiontitle'>".get_string("delete_files", "block_cleanup")."</p>
                <input type='hidden' name='dtype' value='files' />
                <p class='inputtitle'>".get_string("set_ftypes","block_cleanup")."</p>
                <input type='text' name='ftypes' size='10' maxlength='32' value='.jpeg .jpg'/>
                <p class='inputtitle'>".get_string("set_fsize","block_cleanup")."</p>
                <input type='text' name='fsize' size='4' maxlength='10' value='1024'/>
                <input type='submit' name='ud_submit' value='>' title='"
                .get_string('launch_script', 'block_cleanup')."'/>
                </form></div>";
        
        $text .= $form;
        
        $this->content->text   = $text;
        return $this->content;
    }
    
    public function cron() 
    {
        global $CFG;
        mtrace("\n..............BLOCK_CLEANUP CRON SCRIPT HAS STARTED.............");
        if ( intval($CFG->block_cleanup_is_cron) )
		{
			require_once($CFG->libdir."/cleanup/lib.php");
			delete_inactive_data();
		}
        mtrace("\n..............BLOCK_CLEANUP CRON SCRIPT HAS FINISHED.............");
        return true;
    }
    
    function instance_allow_config() {
        return false;
    }
}
?>